﻿namespace Sidvall.CodeGenerator
{
    public class FolderItemCollection : System.Collections.ObjectModel.KeyedCollection<string, FolderItem>
    {
        #region Public Members

        #region Add

        public FolderItem Add(string folderPath, string folderNamespace)
        {
            var item = new FolderItem()
            {
                FolderPath = folderPath,
                Namespace = folderNamespace,
            };
            Add(item);
            return item;
        }

        #endregion
        #region AddOrGetExisting

        public FolderItem AddOrGetExisting(FolderItem item)
        {
            if (item == null)
                return null;
            if (!Contains(item.FolderPath))
            {
                Add(item);
                return item;
            }
            return this[item.FolderPath];
        }

        #endregion
        #region GetKeyForItem

        protected override string GetKeyForItem(FolderItem item)
        {
            if (item == null)
                throw new System.ArgumentNullException("item");
            return item.FolderPath;
        }

        #endregion

        #endregion
        #region Constructors

        public FolderItemCollection()
            : base(System.StringComparer.OrdinalIgnoreCase)
        {
        }

        #endregion
    }
}
